<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item label-width="350"
				:label-position="labelPosition" label="油补距(m)" prop="youBuJu">
				<u-input :border="border" placeholder="请输入油补距" v-model="model.youBuJu" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="末根方入(m)" prop="moGenFangRu">
				<u-input :border="border" placeholder="请输入末根方入" v-model="model.moGenFangRu" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="油管（钻杆）及附件长度(m)" prop="youGuanJiFuJian">
				<u-input :border="border" placeholder="请输入油管（钻杆）及附件长度" v-model="model.youGuanJiFuJian" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="修井工具长度(m)" prop="xiuJingGongJu">
				<u-input :border="border" placeholder="请输入修井工具长度" v-model="model.xiuJingGongJu" type="digit"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
				<u-form-item style="font-size: 22px;" :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="300"
					:label-position="labelPosition" label="修井工具深度" prop="xiuJingGongJuShenDu">
					<span v-if="model.xiuJingGongJuShenDu"> {{model.xiuJingGongJuShenDu}} m </span>
				</u-form-item>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">修井工具深度 = 油补距 + 末根方入 + 油管（钻杆）及附件长度 + 修井工具长度</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					youBuJu: '',
					moGenFangRu: '',
					youGuanJiFuJian: '',
					xiuJingGongJu: '',
					xiuJingGongJuShenDu: ''
				},
				rules: {
					youBuJu: [{
						required: true,
						message: '请输入油补距',
						trigger: 'blur'
					}],
					moGenFangRu: [{
						required: true,
						message: '请输入末根方入',
						trigger: 'blur'
					}],
					youGuanJiFuJian: [{
						required: true,
						message: '请输入油管（钻杆）及附件长度',
						trigger: 'blur'
					}],
					xiuJingGongJu: [{
						required: true,
						message: '请输入修井工具长度',
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,
				
			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						this.model.xiuJingGongJuShenDu = (
							parseFloat(this.model.youBuJu) + 
							parseFloat(this.model.moGenFangRu) + 
							parseFloat(this.model.youGuanJiFuJian) + 
							parseFloat(this.model.xiuJingGongJu)
						).toFixed(2);
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
	}
</style> 